<?php

declare(strict_types=1);

namespace Plugin\Attractions\AttractionManagement\Model;

use Hyperf\DbConnection\Model\Model as MineModel;

/**
 * @property int $id 主键
 * @property string $name 分类名称
 * @property string $description 分类描述
 * @property int $sort 排序
 * @property int $parent_id 父级分类Id
 * @property int $level 分类层级
 * @property \Carbon\Carbon $created_at 
 * @property \Carbon\Carbon $updated_at 
 */
class AttractionType extends MineModel
{
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'attraction_type';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['type', 'name', 'description', 'sort', 'parent_id', 'level'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'type' => 'integer', 'sort' => 'integer', 'parent_id' => 'integer', 'level' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];

    public function infos()
    {
        return parent::hasMany(AttractionInfo::class, 'type_id', 'id');
    }

    public function parent()
    {
        return parent::hasOne(self::class, 'id', 'parent_id');
    }
}